home *** CD-ROM | disk | FTP | other *** search
- #include <gl.h>
- #include <device.h>
- #include <stdio.h>
-
- #include "Reconstruct.h"
-
- #ifndef NULL
- #define NULL 0L
- #endif
-
- extern int Animating;
-
- static long win;
- static int AnimationFrozen;
- static int Outline = FALSE, ShowPoint = FALSE;
-
- static double xL, xH, yL, yH, xl, yl, xh, yh;
-
- AnimateInitialize( XL,YL,XH,YH)
- double XL, XH, YL, YH;
- {
- if (!Animating) return;
-
- xL = xl = XL; xH = xh = YH;
- yL = yl = YL; yH = yh = YH;
- ortho2( (Coord) xL, (Coord) xH, (Coord) yL, (Coord) yH );
- }
-
-
- AnimateShadeCell( Boundary, Sample )
- RectType *Boundary;
- SampleData *Sample;
- {
- short r, g, b;
-
- if (!Animating || AnimationFrozen) return;
-
- r = Sample->Ave.r*256;
- g = Sample->Ave.g*256;
- b = Sample->Ave.b*256;
-
- if (r > 255) r = 255; if (r < 0) r = 0;
- if (g > 255) g = 255; if (g < 0) g = 0;
- if (b > 255) b = 255; if (b < 0) b = 0;
-
- bgnpolygon();
- {
- double p[2];
-
- RGBcolor( r, g, b );
- p[0] = Boundary->xL;
- p[1] = Boundary->yL;
- v2d( p );
-
-
- p[0] = Boundary->xL;
- p[1] = Boundary->yH;
- v2d( p );
-
- p[0] = Boundary->xH;
- p[1] = Boundary->yH;
- v2d( p );
-
- p[0] = Boundary->xH;
- p[1] = Boundary->yL;
- v2d( p );
-
- }
- endpolygon();
-
-
- if (Outline) {
- bgnclosedline();
- {
- double p[2];
-
- RGBcolor( 255, 255, 255 );
-
- p[0] = Boundary->xL;
- p[1] = Boundary->yL;
- v2d( p );
-
- p[0] = Boundary->xL;
- p[1] = Boundary->yH;
- v2d( p );
-
- p[0] = Boundary->xH;
- p[1] = Boundary->yH;
- v2d( p );
-
- p[0] = Boundary->xH;
- p[1] = Boundary->yL;
- v2d( p );
- }
- endclosedline();
- }
-
- if (ShowPoint) {
- bgnpoint();
- {
- double p[2];
-
- p[0] = Sample->Xs; p[1] = Sample->Ys;
- RGBcolor( (short) 255, (short) 255, (short) 255 );
- v2d( p );
- }
- endpoint();
- }
- }
-
-
- void Animate (Animation)
- char *Animation;
- {
- Animating = TRUE;
-
- foreground();
-
- /* Set up default window size and options*/
- prefsize( 768, 768 );
- maxsize ( 1024, 1024 );
- minsize ( 32, 32 );
- keepaspect( 1, 1 );
-
- /* Open the window */
- win = winopen("Delaunay");
-
- /* Initialize the graphics state */
- RGBmode();
- singlebuffer();
- gconfig();
- ortho2(-1.0,1.0,-1.0,1.0);
- clear();
-
- /* Set up devices to queue */
- qdevice( REDRAW );
- qdevice( WINQUIT );
- qdevice( WINFREEZE );
- qdevice( WINTHAW );
-
- qdevice( LEFTMOUSE );
- qdevice( MIDDLEMOUSE );
- tie( MIDDLEMOUSE, MOUSEX, MOUSEY );
- qdevice( RIGHTMOUSE );
-
- qdevice( LEFTARROWKEY );
- qdevice( RIGHTARROWKEY );
- qdevice( DOWNARROWKEY );
- qdevice( UPARROWKEY );
-
- qdevice( F1KEY );
- qdevice( F2KEY );
- qdevice( F3KEY );
- qdevice( F4KEY );
- qdevice( F5KEY );
-
- unqdevice( INPUTCHANGE );
- }
-
-
- static void AnimateReDraw()
- {
- extern HierarchicalRegion Root;
- extern RectType RootBoundary;
- register HierarchicalRegion *Node;
- RectType LeftBoundary, RightBoundary, Boundary, Overlap;
-
- /* This stack is used to avoid the expense of recursion */
- HierarchicalRegion *NodeStack[MAX_DEPTH];
- RectType BoundaryStack[MAX_DEPTH];
- int levelStack[MAX_DEPTH];
- int nStack, level;
-
- if (AnimationFrozen) return;
-
-
- /* Make sure the transformation is restored to the right state */
- reshapeviewport();
-
-
- /* Start with the root node on the stack */
- nStack = 0;
- NodeStack[nStack] = &Root;
- BoundaryStack[nStack] = RootBoundary;
- levelStack[nStack++] = 0;
-
- while (nStack > 0) {
-
- /* Get the next node to process from the stack */
- Node = NodeStack[--nStack];
- Boundary = BoundaryStack[nStack];
- level = levelStack[nStack];
-
- /* Follow the tree down a leaf, pushing the side branches.
- */
- while (! IsLeaf(Node)) {
-
- SplitBoundary( TRUE, Node->splitDirection, Node->splitValue,
- &Boundary, &LeftBoundary );
- if (Node->Left) {
- NodeStack[nStack] = Node->Left;
- BoundaryStack[nStack] = LeftBoundary;
- levelStack[nStack++] = level+1;
- }
- SplitBoundary( FALSE, Node->splitDirection, Node->splitValue,
- &Boundary, &RightBoundary );
- if (Node->Right) {
- if (nStack >= MAX_DEPTH) {
- fprintf( stderr, "Filter stack overflow!\n" );
- abort();
- }
- NodeStack[nStack] = Node->Right;
- BoundaryStack[nStack] = RightBoundary;
- levelStack[nStack++] = level+1;
- }
-
- /* Get the next node to process from the stack */
- Node = NodeStack[--nStack];
- Boundary = BoundaryStack[nStack];
- level = levelStack[nStack];
- }
-
- if (Node == NULL)
- continue; /* Dead end, go back to the stack loop */
-
- AnimateShadeCell( &Boundary, Node->Sample );
- }
- }
-
-
-
- AnimateDoEvent()
- {
- Device dev;
- short data;
- double range;
- int update = FALSE;
-
- if (!Animating) return;
-
- while (qtest()) {
- dev=qread(&data) ;
- switch (dev)
- {
- case REDRAW:
- AnimateReDraw();
- break;
- case WINQUIT:
- exit(0);
- case WINFREEZE:
- AnimationFrozen = TRUE;
- break;
- case WINTHAW:
- AnimationFrozen = FALSE;
- winset( win );
- break;
-
- case F1KEY:
- if (data != 1) break; /* Button down only */
- /* Reset */
- xL = xl; yL = yl; xH=xh; yH=yh;
- update = TRUE;
- break;
-
- case F2KEY:
- if (data != 1) break; /* Button down only */
- Outline = !Outline;
- update = TRUE;;
- break;
-
-
- case F3KEY:
- if (data != 1) break; /* Button down only */
- ShowPoint = !ShowPoint;
- update = TRUE;
- break;
-
- case F4KEY:
- if (data != 1) break; /* Button down only */
- fprintf( stderr, "%lf %lf %lf%lf\n", xL, yL, xH, yH );
- break;
-
- case F5KEY:
- if (data != 1) break;
- fprintf( stderr, "Enter box xl,yl,xh,yh: " );
- {
- FILE *term = fopen( "/dev/tty", "r" );
- int n = fscanf ( term, "%lf %lf %lf %lf", &xL, &yL, &xH, &yH );
- fclose(term);
- }
- update = TRUE;
- break;
-
- case LEFTMOUSE:
- if (data != 1) break; /* Button down only */
- /* Zoom out */
- range = xH - xL;
- range *= 0.05;
- xL -= range;
- xH += range;
-
- range = yH - yL;
- range *= 0.05;
- yL -= range;
- yH += range;
- update = TRUE;
- AnimateReDraw();
- break;
-
- case MIDDLEMOUSE:
- {
- static double xl, yl, xh, yh;
- int x_origin, y_origin, x_size, y_size;
-
- getorigin( &x_origin, &y_origin );
- getsize ( &x_size , &y_size );
-
- if (data == 1) { /* Button Down */
- /* Next two events ought to be mousex and mousey */
- dev = qread( &data );
- xl = (double) (data - x_origin) * (xH - xL) / (x_size) + xL;
- dev = qread( &data );
- yl = (double) (data - y_origin) * (yH - yL) / (y_size) + yL;
- } else { /* Mouse Up */
- /* Next two events ought to be mousex and mousey */
- dev = qread( &data );
- xh = (double) (data - x_origin) * (xH - xL) / (x_size) + xL;
- dev = qread( &data );
- yh = (double) (data - y_origin) * (yH - yL) / (y_size) + yL;
- if (xl > xh) { xL = xh; xH = xl;} else { xL = xl; xH = xh; }
- if (yl > yh) { yL = yh; yH = yl;} else { yL = yl; yH = yh; }
- update = TRUE;
- }
- break;
- }
-
- case RIGHTMOUSE:
- if (data != 1) break; /* Button down only */
- /* Zoom in */
- range = xH - xL;
- range *= 0.05;
- xL += range;
- xH -= range;
-
- range = yH - yL;
- range *= 0.05;
- yL += range;
- yH -= range;
- update = TRUE;
- break;
-
- case LEFTARROWKEY:
- if (data != 1) break; /* Button down only */
- /* Move left (negative) */
- range = xH - xL;
- range *= .05;
- xL -= range;
- xH -= range;
- update = TRUE;
- break;
-
- case RIGHTARROWKEY:
- if (data != 1) break; /* Button down only */
- /* Move right (positive) */
- range = xH - xL;
- range *= .05;
- xL += range;
- xH += range;
- update = TRUE;
- break;
-
- case DOWNARROWKEY:
- if (data != 1) break; /* Button down only */
- /* Move down (negative) */
- range = yH - yL;
- range *= .05;
- yL -= range;
- yH -= range;
- update = TRUE;
- break;
-
- case UPARROWKEY:
- if (data != 1) break; /* Button down only */
- /* Move up (positive) */
- range = yH - yL;
- range *= .05;
- yL += range;
- yH += range;
- update = TRUE;
- break;
-
- }
- }
- if (update) {
- ortho2( (Coord) xL, (Coord) xH, (Coord) yL, (Coord) yH );
- RGBcolor(0,0,0); clear();
- AnimateReDraw();
- }
- return dev;
- }
-
- int AnimateCheckInput()
- {
- if (!Animating) return;
-
- while ( qtest() )
- (void) AnimateDoEvent();
- }
-
-
- AnimateExit()
- {
-
- if (!Animating) return;
-
- do {} while (AnimateDoEvent() != WINQUIT);
- }
-
-
-
-
-